#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+10;
int T,n,m,a[N],b[N],p,ans,ma,oo;
int col[20];
void solve1(){
    for (int i=1;i<=n;i++){
        for (int j=i-1;j>=1;j--){
            if (col[j]==col[i]){
                if (a[j]==a[i]) {
                    ans+=a[i];
                }
                break;
            }
        }
    }
}
void solve2(){
    for (int i=1;i<=n;i++){
        for (int j=i-1;j>=1;j--){
            if (col[a[j]]==col[a[i]]){
                if (a[j]==a[i]) {
                    ans+=a[i];
                }
                break;
            }
        }
    }
}
signed main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>T;
    while (T--){
        cin>>n;
        m=0;ma=0;
        for (int i=1;i<=n;i++){
            cin>>a[i];
            m=max(a[i],m);
        }
        if (n<=15){
            p=pow(2,n)-1;
            for (int o=0;o<=p;o++){
                oo=o;ans=0;
                for (int i=1;i<=n;i++){
                    col[i]=oo%2;
                    oo/=2;
                }
                solve1();
                ma=max(ans,ma);
            }
            cout<<ma<<endl;
        }//20pts
        else if (m<=10){
            p=pow(2,m)-1;
            for (int o=0;o<=p;o++){
                oo=o;ans=0;
                for (int i=1;i<=m;i++){
                    col[i]=oo%2;
                    oo/=2;
                }
                solve2();
                ma=max(ans,ma);
            }
            cout<<ma<<endl;
        }//0~15pts
    }
    return 0;
}
//20~35pts